<%@page import="org.springframework.web.context.request.RequestContextHolder"%>
<%@page import="org.springframework.web.context.request.ServletRequestAttributes"%>
<%@ page session="true" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>        
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
   		<script type="text/javascript" src="<c:url value="/resources/dojo/dojo.js" />"> </script>
		<script type="text/javascript" src="<c:url value="/resources/spring/Spring.js" />"> </script>
		<script type="text/javascript" src="<c:url value="/resources/spring/Spring-Dojo.js" />"> </script>
</head>
<body>

<H3 style="text-align:center;">Generic API Execution</H3>
<!--<P>You can insert a description abou this AIP in here...</P>-->

<br/>

<!----------- Search Box ------------>
<form:form id="GenericAPIExecutionForm" method="get" commandName="GenericAPIExecutionModel" action="api_execution.htm">
    <fieldset>
        <legend>Filtering</legend>

        <table>
            <tr>
                <td style="width:150px;">System Name</td>
                <td style="width:250px">
                 <form:select path="systemName" multiple="false" size="1"  onchange="">
                 <form:options path="systemName" items="${systemCollection}" />
                </form:select>
                </td>
            </tr>
            <tr>
                <td>Package Name</td>
                <td>
                
               <form:select path="packageName" multiple="false" size="1"  style="width:220px"><!--
                    <form:option value="${selectedPackageName}" label="${selectedPackageName}"/> 
                    -->
                    <form:option value=""></form:option>
                    <form:options path="packageName" items="${packageNameCollection}" />
                </form:select>
                </td>
            </tr>
            <tr>
                <td>API Name</td>
                <td>
                    <form:input id="apiName" path="apiName" style="width:220px" />
                   
                </td>
            </tr>
           <tr>
           </tr>
            <tr>
                <td></td>
                <td style="vertical-align:bottom;">
                	<input type="submit" id="app_button_subsction" name="searchAPI" value="Search" class="app_button">
                </td>
                <td></td>
                <td>
                </td>
            </tr>
        </table>

        <fieldset class="small_fielset">
            <div id="show">
                <input type="checkbox" id="c1" name="cc" checked="checked"disabled="disabled" />
                <label for="c1"><span></span> WADL</label>
                <br/>
                <br/>
                <input type="checkbox" id="c2" name="cc" disabled="disabled"/>
                <label for="c2"><span></span> SOAP</label>
                <br/><br/>
                <input type="checkbox" id="c3" name="cc"disabled="disabled" />
                <label for="c3"><span></span> RMI</label>
            </div>
        </fieldset>
    </fieldset>
    <div>
    
    
    
    <!-- ############################ Under Construction ######################### -->
    <br/>
    <fieldset class="result_fieldset">
        <legend>API Signatures</legend>
        
		<c:forEach items="${GenericAPIExecutionPageController_genericAPISearchResultsView}" var="api">
           <span class="radioButtonDiv_style">
				<form:radiobutton  id="${api.apiId}" path="apiId" value="${api.apiId}" onclick="feedHiddenData(${api.apiId},'','${api.apiName}')"/> 
				<span >
				    <label>${api.apiName}</label>
					<form:input class="textbox" type="text" id="${api.apiId}FiledId" path="packageName" value="${api.packageStructure}" onblur="feedQueryParamData('${api.apiId}')"/>
				</span>
				<br>
           </span>
		</c:forEach>
        <br/>

        <div style="padding-top:10px;float:right;">        
                <input type="submit" id="app_button_subsction" name="Load" value="Load" class="app_button">
        </div>
    </fieldset>
    <!-- ######################################################################## -->    
    
    
    
</div>
<br/>
<!----------- Input String Box ------------>
<div>
    <fieldset>
        <legend>API Parameters</legend>

        <table>
            <tr>     
                <!--<form:textarea id="consumercontentId" style="width:530px"  path="consumerString" onkeyup="feedHiddenData('','consumercontentId')"/>

                --><textarea id="consumercontentId" name="consumerString" cols="60" rows="40" onblur="feedHiddenData('','consumercontentId','')" ><c:out value="${GenericAPIExecutionModel.consumerString}"/></textarea>
                </tr>
        </table>

        <div class="subSection_button_panel">
		<tr>
                <td>                
                   <a href="<c:url value='/popup_api_selection.htm' />" id="apiload" >
            			<input type="submit" id="app_button_subsction" name="Submit" value="Select"    class="app_button">
 				  </a> 
	
                </td>
                <td style="vertical-align:bottom;">
					<a onclick="" href="<c:url value='/popup_save_template_window.htm'/>" id="apisave">
                    	<input type="submit" id="app_button_subsction" name="SaveTemplate" value="Save" class="app_button">
 					</a>      
                </td>
                
         </tr>
        </div>
        
    </fieldset>
    
</div>
  <br/>  
 <!-- Buttons -->
<div style="height:25px;margin-left:545px">
<a onclick="" href="<c:url value='/submitCall.htm'/>" id="submitApi">
    <input type="submit" id="app_button" name="Submit" value="Submit" class="app_button">
</a>
    <input type="submit" id="app_button" name="Clear" value="Clear" class="app_button">
</div>
<br/>

</form:form>

<!-- Result Table  -->
<section id="content_result">

    <div class="resultTable_header">Result Table</div>

    <table id="table-4">
        <thead>
        <tr>
            <th></th>
            <th>API Name</th>
            <th>Input parameter</th>
            <th>Result</th>
        </tr>
        </thead>
        <tbody>
              
        <c:forEach items="${GenericAPIExecutionPageController_ResultView}" var="result">
          <tr> <td style="width:10px">
                <input type="checkbox" id="c3" name="cc"/>
                <label for="c3"><span></span></label>
            </td>
				<td>${result.apiName}</td>
				<td>${result.inputParams}</td>
				<td>${result.result}</td>
				<td>
				<a href="downloadResultXML.htm?RecordId=${result.recordId}" name="Result"
                               class="button">View Result</a>
                </td> 
          <tr> 
		</c:forEach>  
		    
        </tbody>
    </table>
</section>
<br/>

<!--- ############################################################################################################# --->

<div id="apiSaveForm">
	<script type="text/javascript">
		dojo.addOnLoad(function() {
			Spring.addDecoration(new Spring.AjaxEventDecoration({
    			elementId:'apisave', 
    			event:'onclick',
    			popup:true,
    			params: {fragments: "template_save_main_dev_id"}
    		}));
		});
	</script>
</div>

<script type="text/javascript">
		dojo.addOnLoad(function() {
			Spring.addDecoration(new Spring.AjaxEventDecoration({
    			elementId:'apiload', 
    			event:'onclick',
    			popup:true,    			
    			params: {fragments: "popup_main_layout_body"}
    		}));
		});
</script>

<script type="text/javascript">
		dojo.addOnLoad(function() {
			Spring.addDecoration(new Spring.AjaxEventDecoration({
    			elementId:'apiSignatureUpdate', 
    			event:'onclick',
    			popup:true,    			
    			params: {fragments: "api_change_dev_id"}
    		}));
		});
</script>



<!-- This is a utility JSP that closes any Dojo Modal dialogs -->
<script type="text/javscript">
dojo.query(".dijitDialog").forEach(function(element) {
	dijit.byId(element.id).hide();
});
</script>

<script type="text/javascript">
function feedHiddenData(apiId,consumerString,apiSignature){

	var content;
	textareaid = document.getElementById(consumerString);

	if(textareaid != null){
		content = textareaid.value;
	}
	
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.open("GET","feed_hidden_data.htm?apiId=" + apiId + "&consumerString=" + content + "&apisignature=" + apiSignature, true);
	xmlhttp.send();
	
}

function feedQueryParamData(apiId){

	var urlParam;
	var elementId = apiId+"FiledId";

	textareaid = document.getElementById(elementId);
	
	if(textareaid != null){
		urlParam = textareaid.value;
	}

	var xmlhttp = new XMLHttpRequest();
	xmlhttp.open("GET","feed_query_param.htm?apiId=" + apiId + "&urlParam=" + urlParam, true);
	xmlhttp.send();
}

        
</script>

					
</body>
</html>






